package com.zsinfo.guoss.supplier.activity;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;

import com.example.netcenter.Event.Response;
import com.example.netcenter.RetrofitBuilder;
import com.example.netcenter.Url.ConstantsCode;
import com.example.netcenter.bean.RegisterBean;
import com.zsinfo.guoss.supplier.MainActivity;
import com.zsinfo.guoss.supplier.R;
import com.zsinfo.guoss.supplier.base.BaseActivity;
import com.zsinfo.guoss.supplier.logichelper.LoginAndRegisterHelper;
import com.zsinfo.guoss.supplier.utils.SharedPreferencesUtil;

public class StartActivity extends BaseActivity {


    Handler handler = new Handler();

    @Override
    protected int getContentLayoutRes() {
        return R.layout.activity_start;
    }

    @Override
    protected void initView() {

        setShowTitle(false);

    }

    @Override
    protected void initNetData() {
//        handler.postDelayed(new Runnable() {
//            @Override
//            public void run() {
//                StartApp();
//            }
//        }, 2000);
//
//



        try {
            Thread.sleep(2000);
            StartApp();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }



    }


    protected void StartApp() {
        if (SharedPreferencesUtil.getToken().isEmpty()) {

            StartActivityByNoIntent(LoginPwdActivity.class);

            finish();

        } else {

            GetNetCenter().GetNetCenter(

                    RetrofitBuilder.CreateApi().LOGIN(

                            ConstantsCode.supplier_login,

                            SharedPreferencesUtil.getToken()),

                    new Response() {
                        @Override
                        public void OK(Object data) {

                            RegisterBean registerBean = (RegisterBean) data;
                            LoginAndRegisterHelper loginAndRegisterHelper = new LoginAndRegisterHelper();
                            loginAndRegisterHelper.SaveInfo(registerBean);
                            StartActivityByNoIntent(MainActivity.class);
                            finish();
                        }

                        @Override
                        public void Fail(Throwable e) {

                            showToast(e.getLocalizedMessage());
                            StartActivityByNoIntent(LoginPwdActivity.class);
                            finish();

                        }

                        @Override
                        public void complete() {

                        }
                    });

        }
    }

    @Override
    protected void customDestroy() {

    }
}
